home *** CD-ROM | disk | FTP | other *** search
/ Programming in Microsoft Windows with C# / Programacion en Microsoft Windows con C#.iso / Codigo / Páginas y transformaciones / WhatSize / WhatSize.cs next >
Encoding:
Text File  |  2002-05-06  |  1.3 KB  |  46 lines

  1. //---------------------------------------
  2. // WhatSize.cs ⌐ 2001 by Charles Petzold
  3. //---------------------------------------
  4. using System;
  5. using System.Drawing;
  6. using System.Drawing.Drawing2D;
  7. using System.Windows.Forms;
  8.  
  9. class WhatSize: PrintableForm
  10. {
  11.      public new static void Main()
  12.      {
  13.           Application.Run(new WhatSize());
  14.      }
  15.      public WhatSize()
  16.      {
  17.           Text = "┐QuΘ tama±o?";
  18.      }
  19.      protected override void DoPage(Graphics grfx, Color clr, int cx, int cy)
  20.      {
  21.           Brush brush = new SolidBrush(clr);
  22.           int   y     = 0;
  23.  
  24.           DoIt(grfx, brush, ref y, GraphicsUnit.Pixel);
  25.           DoIt(grfx, brush, ref y, GraphicsUnit.Display);
  26.           DoIt(grfx, brush, ref y, GraphicsUnit.Document);
  27.           DoIt(grfx, brush, ref y, GraphicsUnit.Inch);
  28.           DoIt(grfx, brush, ref y, GraphicsUnit.Millimeter);
  29.           DoIt(grfx, brush, ref y, GraphicsUnit.Point);
  30.      }
  31.      void DoIt(Graphics grfx, Brush brush, ref int y, GraphicsUnit gu)
  32.      {
  33.           GraphicsState gs = grfx.Save();
  34.  
  35.           grfx.PageUnit  = gu;
  36.           grfx.PageScale = 1;
  37.  
  38.           SizeF sizef = grfx.VisibleClipBounds.Size;
  39.  
  40.           grfx.Restore(gs);
  41.  
  42.           grfx.DrawString(gu + ": " + sizef, Font, brush, 0, y);
  43.           y += (int) Math.Ceiling(Font.GetHeight(grfx));
  44.      }
  45. }
  46.